package fs_cmd

import (
	"context"
	"fmt"

	"atomgit.com/openlinksaas/extension-proto-gen-go.git/extension_fs_api"
	"atomgit.com/openlinksaas/extension-test-cli/utils"
	"github.com/spf13/cobra"
)

var _removeCmd = &cobra.Command{
	Use:   "remove",
	Short: "remove file",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if len(args) != 2 {
			return fmt.Errorf("miss param:[fsId] [fileId]")
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		conn, err := utils.ConnServer()
		if err != nil {
			return err
		}
		defer conn.Close()

		client := extension_fs_api.NewExtensionFsApiClient(conn)
		fsId := args[0]
		fileId := args[1]

		_, err = client.RemoveFile(context.Background(), &extension_fs_api.RemoveFileRequest{
			FsId:   fsId,
			FileId: fileId,
		})
		if err != nil {
			return err
		}
		fmt.Printf("remove %s/%s success\n", fsId, fileId)
		return nil
	},
}
